package ch.ethz.fcl.metrobuzz.controller.gui.twl.treetable;

import ch.ethz.fcl.metrobuzz.render.interchange.mrt.MRTInterchangeRender;
import de.matthiasmann.twl.model.BooleanModel;
import de.matthiasmann.twl.model.HasCallback;

public class MBBooleanModel extends HasCallback implements BooleanModel {
	private final String prefKey;
	private boolean value;

	public MBBooleanModel(String prefKey, boolean defaultValue) {
		if (prefKey == null) {
			throw new NullPointerException("prefKey");
		}
		this.prefKey = prefKey;
		value = defaultValue;
	}

	public boolean getValue() {
		return value;
	}

	public void setValue(boolean value) {
		if (this.value != value) {
			this.value = value;
			valueChanged(value);
			doCallback();
		}
	}

	private void valueChanged(boolean value) {
		if (prefKey.equalsIgnoreCase("EW"))
			MRTInterchangeRender.EWRender = value;
		else if (prefKey.equalsIgnoreCase("NS"))
			MRTInterchangeRender.NSRender = value;
		else if (prefKey.equalsIgnoreCase("NE"))
			MRTInterchangeRender.NERender = value;
		else if (prefKey.equalsIgnoreCase("CC"))
			MRTInterchangeRender.CCRender = value;
	}
}